﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tunneler.Tools;

using Microsoft.Xna.Framework;

namespace Tunneler {
    class Camera {
        Vector2 center = new Vector2();
        Matrix transform;
        World world;

        int horizontalOffset;
        int verticalOffset;

        public Matrix Transform { get { return transform; } }

        public Camera(World world, int horizontalOffset, int verticalOffset) {
            this.world = world;
            this.horizontalOffset = horizontalOffset;
            this.verticalOffset = verticalOffset;
        }

        public void Update(GameTime gameTime, Vector2 position) {
            center.X = position.X - (Game1.SCREEN_WIDTH - horizontalOffset) / 4;
            center.Y = position.Y - (Game1.SCREEN_HEIGHT - verticalOffset) / 2;

            center.X = Math.Max(0, center.X);
            center.X = Math.Min(center.X, world.Terrain.Width - Game1.SCREEN_WIDTH / 2 + horizontalOffset);
            center.Y = Math.Max(0, center.Y);
            center.Y = Math.Min(center.Y, world.Terrain.Height - Game1.SCREEN_HEIGHT + verticalOffset);

            transform = Matrix.CreateScale(new Vector3(1, 1, 0)) * Matrix.CreateTranslation(new Vector3(-center, 0));
        }
    }
}
